from rest_framework import serializers
from apps.login.models import UserInfo


class LoginSerializers(serializers.Serializer):
    nickName = serializers.CharField(label="微信名称")
    avatarUrl = serializers.CharField(label="头像url")
    token = serializers.CharField(label="用户token",allow_blank=True)
    registrationTime = serializers.DateTimeField(label="用户注册时间",read_only=True,format="%Y-%m-%d %H:%M")

    def validate(self, attrs):
        # if len(attrs['token']) != 0:
        #     raise serializers.ValidationError("用户token已存在")
        return attrs


    # 重写create方法，用于保存数据
    def create(self, validated_data):
        data = UserInfo(**validated_data)
        data.save()
        return validated_data